package org.devgframwork.datasync.admin.support.init.impl;

import lombok.extern.slf4j.Slf4j;
import org.devgframwork.datasync.admin.rabbit.service.CanalConfigService;
import org.devgframwork.datasync.admin.support.init.AbstractInit;
import org.devgframwork.datasync.core.entity.CanalConfig;
import org.devgframwork.datasync.core.support.DataSourceCanal;
import org.devgframwork.datasync.core.support.DataSourceMemory;
import org.devgframwork.datasync.core.utils.CommonUtil;
import java.util.List;

@Slf4j
public class CanalInit extends AbstractInit {


    public CanalInit(AbstractInit nextAbstractInit) {
        super(nextAbstractInit);
    }

    @Override
    public void initComponent() {
        CanalConfigService canalConfigService = DataSourceMemory.applicationContext.getBean(CanalConfigService.class);
        List<CanalConfig> canalConfigList = canalConfigService.getCanalConfigList();
        if (CommonUtil.isEmpty(canalConfigList)) {
            log.warn("canalConfigList is empty");
            return;
        }
        for (CanalConfig canalConfig : canalConfigList) {
            new Thread(new DataSourceCanal(canalConfig)).start();
        }
        log.info("init canal finish ... ");
    }
}
